﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Recon.Portal.Business;
using Recon.Portal.DataObjects;

namespace Recon.Portal.WebUI
{
    public partial class SearchBank : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                control.Value = Request.QueryString["textbox"].ToString();
                path.Value = Request.QueryString["PageRequest"].ToString();
                BindGrid();
                txtBankId.Focus();

            }
        }

        #region User Defined Function

        public void BindGrid()
        {
            try
            {
                BankDAO bankDAO = DAOFactory.getBankDAO();
                if (txtBankId.Text.Trim() == "")
                {

                    List<Bank> bankLst = bankDAO.getAllBanks();
                    // dtUserDetails = objDBfactory.GetCustomerDetailsByBankId(Convert.ToString(control.Value).Trim());

                    if (bankLst == null)
                    {
                        lblBankcnt.Text = "No Records Found";
                    }
                    else if (bankLst.Count >= 1)
                    {
                        gvBank.DataSource = bankLst;
                        gvBank.DataBind();
                        lblBankcnt.Text = bankLst.Count.ToString() + " records found.";
                    }
                    else
                    {
                        lblBankcnt.Text = "No Records Found";
                    }
                }
                else
                {
                    Bank bank = bankDAO.getBank(Convert.ToString(txtBankId.Text).Trim());
                    // dtUserDetails = objDBfactory.GetCustomerDetailsByBankId(Convert.ToString(txtBankId.Text).Trim());

                    if ((bank) == null)
                    {
                        lblBankcnt.Text = "No Records Found";
                    }
                    else //if (dtUserDetails.Rows.Count >= 1)
                    {
                        List<Bank> bankLst = new List<Bank>();
                        bankLst.Add(bank);
                        gvBank.DataSource = bankLst;
                        gvBank.DataBind();
                        lblBankcnt.Text = bankLst.Count.ToString() + " records found.";
                    }

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
        }

        #endregion
        #region Gridview Events

        protected void btnsearch_Click(object sender, EventArgs e)
        {
            BindGrid();
        }

        protected void gvBank_SelectedIndexChanged(object sender, EventArgs e)
        {
            string Bankid;
            Bankid = ((LinkButton)gvBank.SelectedRow.FindControl("lbtnBankid")).Text;
            string strScript = "<script>";
            strScript += "window.opener.document.all('ctl00$BodyHolder$txtBankID').value = '" + Bankid + "';";
            strScript += "self.close();</script>";
            Response.Write(strScript);
        }
        #endregion
    }
}